﻿//===============================================================================
// Microsoft Platform Architecture Team
// LitwareHR - S+S Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GeoRss;

namespace GeoRSSTest
{
    /// <summary>
    /// Summary description for TestGeoRSS
    /// </summary>
    [TestClass]
    public class PolygonAndLineFixture
    {
        public PolygonAndLineFixture()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion
                
        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void AddsPolygonWithInsufficentCoordinatesThrows()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            Point[] polygon = {new Point(1.1, 2.2), new Point(3.3, 4.4)};
            grssb.AddPolygon( "title", "content", polygon );
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void AddsOpenPolygonThrows()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            Point[] polygon = { new Point( 1.1, 2.2), new Point(3.3, 4.4 ), new Point( 5.5, 6.6) };
            grssb.AddPolygon("title", "content", polygon);
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void CreateOpenPolygonThrows()
        {
            Point[] polygonData = { new Point(1.1, 2.2), new Point(3.3, 4.4), new Point(5.5, 6.6) };
            GeoRssPolygonItem polygon = new GeoRssPolygonItem(polygonData);
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void CreatePolygonWithInsufficientCoordinatesThrows()
        {
            Point[] polygonData = { new Point(1.1, 2.2), new Point(3.3, 4.4) };
            GeoRssPolygonItem polygon = new GeoRssPolygonItem(polygonData);
        }

        [TestMethod]
        public void AddsPolygon()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            Point[] polygon = { new Point( 1.1, 1.1), new Point( 2.2, 2.2), new Point( 1.1, 1.1) };
            grssb.AddPolygon("title", "content", polygon);
            Assert.AreEqual(3, (grssb.Items[0] as GeoRssPolygonItem).Polygon.Count);
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Icon));
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Link));
            Assert.AreEqual("2.2 2.2", (grssb.Items[0] as GeoRssPolygonItem).Polygon[1].ToString());
        }

        [TestMethod]
        public void CreatesPolygonAndAddsToGeoData()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            Point[] polygonData = { new Point(1.1, 1.1), new Point(2.2, 2.2), new Point(1.1, 1.1) };
            GeoRssPolygonItem polygon = new GeoRssPolygonItem(polygonData);
            grssb.Items.Add(polygon);
            Assert.AreEqual(3, (grssb.Items[0] as GeoRssPolygonItem).Polygon.Count);
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Icon));
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Link));
            Assert.AreEqual("2.2 2.2", (grssb.Items[0] as GeoRssPolygonItem).Polygon[1].ToString());
        }


        [TestMethod]
        public void AddsPolygonAndIcon()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            Point[] polygon = { new Point(1.1, 1.1), new Point(2.2, 2.2), new Point(1.1, 1.1) };
            grssb.AddPolygon("title", "content", polygon).Icon = "icon";
            Assert.AreEqual(3, (grssb.Items[0] as GeoRssPolygonItem).Polygon.Count);
            Assert.AreEqual("icon", grssb.Items[0].Icon);
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Link));
            Assert.AreEqual( "2.2 2.2", (grssb.Items[0] as GeoRssPolygonItem).Polygon[1].ToString() );
        }

        [TestMethod]
        public void AddsPolygonAsString()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            grssb.AddPolygon("title", "content", "1.1 1.1 2.2 2.2 1.1 1.1");
            Assert.AreEqual(3, (grssb.Items[0] as GeoRssPolygonItem).Polygon.Count);
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Icon));
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Link));
            Assert.AreEqual("2.2 2.2", (grssb.Items[0] as GeoRssPolygonItem).Polygon[1].ToString());
        }

        [TestMethod]
        public void AddsPolygonAsStringAndIcon()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            grssb.AddPolygon("title", "content", "1.1 1.1 2.2 2.2 1.1 1.1").Icon = "icon";
            Assert.AreEqual(3, (grssb.Items[0] as GeoRssPolygonItem).Polygon.Count);
            Assert.AreEqual("icon", grssb.Items[0].Icon);
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Link));
            Assert.AreEqual("2.2 2.2", (grssb.Items[0] as GeoRssPolygonItem).Polygon[1].ToString());
        }

        [TestMethod]
        public void AddsLine()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            Point[] line = { new Point(1.1, 1.1), new Point(2.2, 2.2) };
            GeoRssLineItem item = grssb.AddLine("title", "content", line );
            Assert.AreEqual(2, item.Line.Count);
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Link));
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Icon));
            Assert.AreEqual( "2.2 2.2", (grssb.Items[0] as GeoRssLineItem).Line[1].ToString() );
        }

        [TestMethod]
        public void AddsLineAndIcon()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            Point[] line = { new Point(1.1, 1.1), new Point(2.2, 2.2) };
            GeoRssLineItem item = grssb.AddLine("title", "content", line);
            item.Icon = "icon";
            Assert.AreEqual(2, item.Line.Count);
            Assert.AreEqual("icon", item.Icon);
            Assert.IsTrue(String.IsNullOrEmpty(grssb.Items[0].Link));
            Assert.AreEqual( "2.2 2.2", (grssb.Items[0] as GeoRssLineItem).Line[1].ToString() );
        }

        [TestMethod]
        public void AddsLineAsString()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            GeoRssLineItem item = grssb.AddLine("title", "content", "1.1 1.1 2.2 2.2");
            Assert.AreEqual(2, item.Line.Count);
            Assert.AreEqual(1.1, item.Line[0].Latitude);
            Assert.AreEqual(1.1, item.Line[0].Longitude);
            Assert.IsTrue(string.IsNullOrEmpty(item.Icon));
            Assert.IsTrue(string.IsNullOrEmpty(item.Link));
        }

        [TestMethod]
        public void AddsLineAsStringAndIcon()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            GeoRssLineItem item = grssb.AddLine("title", "content", "1.1 1.1 2.2 2.2");
            item.Icon = "icon";
            Assert.AreEqual(2, item.Line.Count);
            Assert.AreEqual(1.1, item.Line[0].Latitude);
            Assert.AreEqual(1.1, item.Line[0].Longitude);
            Assert.AreEqual("icon", item.Icon);
            Assert.IsTrue(string.IsNullOrEmpty(item.Link));
        }

        [TestMethod]
        public void AddsLineWithIconAndLink()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            GeoRssLineItem item = grssb.AddLine("title", "content", "1.1 1.1 2.2 2.2");
            item.Icon = "icon";
            item.Link = "somelink";
            Assert.AreEqual(2, item.Line.Count);
            Assert.AreEqual(1.1, item.Line[0].Latitude);
            Assert.AreEqual(1.1, item.Line[0].Longitude);
            Assert.AreEqual("icon", item.Icon);
            Assert.AreEqual("somelink", item.Link);
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void AddLineWithInsufficientPointsAsStringThrows()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            GeoRssLineItem item = grssb.AddLine("title", "content", "1.1 1.1 2.2 2.2 3.3");
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void AddLineWithInsufficientPointsThrows()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            Point[] line = { new Point(1.1, 1.1) };
            GeoRssItem item = grssb.AddLine( "title", "content", line );
        }
    }
}
